#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author : Leiyh
# @File : conftest.py


import pytest




def authorize():
    from base import get_config
    from base.get_config import get_header_file
    from base.getdata import get_header
    from util.report import log_tool
    from base import globalvars as glo
    from util.api import request_tool

    api_url = glo.get_value("url1")
    url = api_url + '/api/user/oauth/authorize'
    log_tool.info('\n请求地址：\n' + url)
    # 获取用户名和密码
    username=get_config.get_value("User", "username")
    password=get_config.get_value("User", "password")
    # 是否鉴权
    authentication = get_config.get_value("Authentication", "authentication")
    # 动态获取json数据
    d = get_header(get_header_file(), "header1")
    headers = d
    req = {
        "emailOrUsername": username,
        "password": password,
        "type": "2",
        "clientId": "7fc231dcb32f88ba5c2d86603304a48d",
        "captcha": ""
    }
    if authentication=='True':
        resp = request_tool.post(url, headers=headers, json=req)
        data = resp.json()
        d = {"token": data["userToken"], "userId": data["userId"], "username": username}
        return d
    else:
        d = {"token": "", "userId": "", "username": ""}
        return d



@pytest.fixture(scope='session')
def pub_data():
    data = {"login": authorize(),"region_scope":""}
    # data = {"login": authorize()}
    yield data